<?php

require_once 'init.php';
require_once 'cf/mail.inc';

$tourId = $par->asInt('tourId');
$tour = getTours(array('id'=>$tourId));
$smarty->assign('tour',$tour[0]);

$msg = '';

if ($par->exist('request'))
{
	$name = $par->asStr('name');					$smarty->assign('name',$name);
	$surname = $par->asStr('surname');				$smarty->assign('surname',$surname);
	$email = $par->asStr('email');					$smarty->assign('email',$email);
	$city = $par->asStr('city');					$smarty->assign('city',$city);
	$country = $par->asStr('country');				$smarty->assign('country',$country);
	$participants = $par->asInt('participants');	$smarty->assign('participants',$participants);
	$remarks = $par->asStr('remarks');				$smarty->assign('remarks',$remarks);
	
	if (!strlen($name) || !strlen($email))
	{
		$msg = getString('Please, fill all obligatory fields');
	}
	else if ($par->asInt('test') != $par->asInt('a'))
	{
		$msg = getString('Sorry, the answer to the security calculation is wrong.');
	}
	else
	{
		$subject = "Request for diving in the Red Sea with Yalladive";
		
		$text = "
			Tour: {$tour[0]['start_date']}-{$tour[0]['end_date']}, {$tour[0]['boat_name']}, {$tour[0]['rout_name']} <br>
			First name: $name <br>
			Surname: $surname <br>
			Email: <a href='mailto:$email'>$email</a> <br>
			City: $city <br>
			Country: $country <br>
			Number of participants: $participants <br>
			Remarks: $remarks <br>
		";

		$m = new Mail($subject, $text);
		$m->setTypeHTML();
		$m->setFrom($settings->admin_email);
		
		Mail::send($settings->admin_email,$m);
		
		$msg = getString('Your request has been transmitted successfully!<br> A yalladive team member will contact you by email.');

		$smarty->assign('send',true);	
	}
}

$smarty->assign('msg',$msg);

$num1 = rand(1,5);
$num2 = rand(5,9);

$smarty->assign('num1',$num1);
$smarty->assign('num2',$num2);
$smarty->assign('numResult',$num1+$num2);

$smarty->assign(
	'page', 
	new SitePage(
		false, 
		false, 
		getString('Request tour'), 
		getString('Request tour'), 
		false
	)
);


show(
	'request', 
	getString('Request tour')
);

?>